# -*- coding: utf-8 -*-
"""
@Time    : 2024/9/12 19:28 
@Author  : ZhangShenao 
@File    : 3.数字时钟.py
@Desc    : 数字时钟
"""
import time


class Clock:
    """数字时钟类"""

    def __init__(self, hour: int = 0, minute: int = 0, second: int = 0):
        """
        构造函数
        :param hour: 时
        :param minute: 分
        :param second: 秒
        """

        # 初始化时分秒
        # 属性采用_开头,表示约定为私有属性,但是在语法层面没有强制校验
        self._hour = hour
        self._minute = minute
        self._second = second

    def tick(self):
        """
        时钟走秒
        """

        # 更新时、分、秒
        self._second += 1
        if self._second >= 60:
            self._second = 0
            self._minute += 1
            if self._minute >= 60:
                self._minute = 0
                self._hour += 1
                if self._hour >= 24:
                    self._hour = 0

    def print_time(self):
        """
        打印时间
        """

        print(f"当前时间为: {self._hour:02d}:{self._minute:02d}:{self._second:02d}")


if __name__ == '__main__':
    # 创建Clock对象
    clock = Clock(hour=23, minute=59, second=50)

    # 时钟开始读秒
    while True:
        clock.print_time()
        time.sleep(1)
        clock.tick()
